package org.example.linkedList;

import java.util.Arrays;

/**
 * @Auther: wangbw
 * @Date:2020/12/10
 * @Description: org.example.linkedList
 * @version: 1.0
 */
public class SelectionSort {
    public static void main(String[] args) {
        int[] arr = new int[]{4, 5, 3, 2, 8};
        sort(arr);
        print(arr);
    }

    private static void sort(int[] arr) {
        for (int i = 0; i < arr.length -1; i++) {
            int k = i;
            for (int j = k + 1; j < arr.length; j++) {
                if(arr[j] < arr[k]){
                    k = j;
                }
            }
            int val = arr[i];
            arr[i] = arr[k];
            arr[k] = val;
        }
    }

    private static void print(int[] arr) {
        System.out.println("result:" + Arrays.toString(arr));
    }
}
